package com.hl.service.impl;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import com.hl.service.ILiliShopMemberService;
//import jdk.nashorn.internal.objects.annotations.Where;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import com.hl.mapper.LiliShopMemberMapper;
import com.hl.domain.LiliShopMember;
import com.hl.service.HuishouMemberService;

/**
 * 会员列表Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-05
 */
@Service
@Primary
public class LiliShopMemberServiceImpl implements ILiliShopMemberService
{
    @Autowired
    private LiliShopMemberMapper liliShopMemberMapper;
@Autowired
    private RedisTemplate redisTemplate;
@Autowired
private PasswordEncoder passwordEncoder;
    /**
     * 查询会员列表
     * 
     * @param memberId 会员列表主键
     * @return 会员列表
     */
    @Override
    public LiliShopMember selectLiliShopMemberByMemberId(String memberId)
    {
        return liliShopMemberMapper.selectLiliShopMemberByMemberId(memberId);
    }

    /**
     * 根据会员名查询会员
     * 
     * @param memberName 会员名
     * @return 会员列表
     */
    @Override
    public LiliShopMember selectLiliShopMemberByMemberName(String memberName)
    {
        return liliShopMemberMapper.selectLiliShopMemberByMemberName(memberName);
    }

    /**
     * 查询会员列表列表
     * 
     * @param liliShopMember 会员列表
     * @return 会员列表
     */
    @Override
    public List<LiliShopMember> selectLiliShopMemberList(LiliShopMember liliShopMember)
    {
        return liliShopMemberMapper.selectLiliShopMemberList(liliShopMember);
    }

    /**
     * 新增会员列表
     * 
     * @param liliShopMember 会员列表
     * @return 结果
     */
    @Override
    public int insertLiliShopMember(LiliShopMember liliShopMember)
    {
        //生成唯一uuid用户标识并判断是否之前存在相同的uuid
        //如果存在则重新生成直到不存在为止
        //如果不存在则将uuid作为用户标识并将用户信息存储到redis中
        String uuid=UUID.randomUUID().toString();
        Boolean flag = redisTemplate.hasKey(uuid);
        while (flag){
            uuid=UUID.randomUUID().toString();
            flag = redisTemplate.hasKey(uuid);
        }
        redisTemplate.opsForValue().set(uuid,liliShopMember.getMemberName());
        liliShopMember.setMemberUuid(uuid);
        //设置注册时间
        liliShopMember.setRegisterTime(new Date());
        //密码加密
        liliShopMember.setPassword(passwordEncoder.encode(liliShopMember.getPassword()));
        //设置默认角色为用户
        liliShopMember.setRoleId(2);
       //设置性别默认为未知
liliShopMember.setGender("unknown");
        return liliShopMemberMapper.insertLiliShopMember(liliShopMember);
    }

    /**
     * 修改会员列表
     * 
     * @param liliShopMember 会员列表
     * @return 结果
     */
    @Override
    public int updateLiliShopMember(LiliShopMember liliShopMember)
    {
        return liliShopMemberMapper.updateLiliShopMember(liliShopMember);
    }

    /**
     * 批量删除会员列表
     * 
     * @param memberIds 需要删除的会员列表主键
     * @return 结果
     */
    @Override
    public int deleteLiliShopMemberByMemberIds(String[] memberIds)
    {
        return liliShopMemberMapper.deleteLiliShopMemberByMemberIds(memberIds);
    }

    /**
     * 删除会员列表信息
     * 
     * @param memberId 会员列表主键
     * @return 结果
     */
    @Override
    public int deleteLiliShopMemberByMemberId(String memberId)
    {
        return liliShopMemberMapper.deleteLiliShopMemberByMemberId(memberId);
    }
}
